from matplotlib import pyplot as plt
from sklearn.decomposition import PCA
from sklearn.cluster import KMeans
from load_data import data
import numpy as np

data = data()
pca = PCA(2)
df = pca.fit_transform(data) #PCA把中心标准化后的数据降维到2-维空间
kmeans = KMeans(n_clusters=3)
label = kmeans.fit_predict(df) #预测簇的标签
u_labels = np.unique(label)

for i in u_labels:
    plt.scatter(df[label == i, 0], df[label == i, 1], label=i)
plt.legend()
plt.show()